/**
 * Created by Simon on 2017/4/14.
 */

$(function () {
  new Vue({
    el: '#vegetable-container',
    data: {
      editingItem: {},
      isFormShow: false
    },
    methods: {
      onAddClick: function () {
        this.editingItem = {};
        this.isFormShow = true;
      },
      onEditClick: function (id) {
        $.get(`/manage/getVegetableById?id=${id}`, res => {
          this.editingItem = res;
          this.isFormShow = true;
        });
      },
      onDeleteClick: function (id) {
        $.get(`/manage/deleteVegetableById?id=${id}`, res => {
          window.location.reload();
        })
      },
      onSubmitClick: function () {
        this.$refs['form'].submit();
      }
    },
    computed: {
      isSubmitEnabled: function () {
        return this.cnName && this.enName && this.spaName
      }
    }
  });
});